package com.serviceprovider.business.module.admin.bonus.model;

//~--- non-JDK imports --------------------------------------------------------

import com.serviceprovider.business.module.admin.role.model.Role;
import com.serviceprovider.business.module.user.model.impl.User;

//~--- JDK imports ------------------------------------------------------------

import java.util.List;

public class Bonus {
    private boolean            active = true;
    private List<BonusPayment> bonusPayments;
    private String             columnName;
    private Integer            customerCount;
    private String             description;
    private BonusDetails       details;
    private Integer            id;
    private Integer            methodId;
    private String             name;
    private String             operator;
    private Double             payPerUnit;
    private String             payUnit;
    private Integer            providerCount;
    private List<Role>         roles;
    private String             tableName;
    @SuppressWarnings("rawtypes")
    private List               tableNameList;
    private Integer            transactionCount;
    private Integer            typeId;
    private List<User>         users;

    @SuppressWarnings("rawtypes")
    public List getTableNameList() {
        return tableNameList;
    }

    @SuppressWarnings("rawtypes")
    public void setTableNameList(List tableNameList) {
        this.tableNameList = tableNameList;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getTypeId() {
        return typeId;
    }

    public void setTypeId(Integer typeId) {
        this.typeId = typeId;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public BonusDetails getDetails() {
        return details;
    }

    public void setDetails(BonusDetails details) {
        this.details = details;
    }

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    public Integer getProviderCount() {
        return providerCount;
    }

    public void setProviderCount(Integer providerCount) {
        this.providerCount = providerCount;
    }

    public Integer getCustomerCount() {
        return customerCount;
    }

    public void setCustomerCount(Integer customerCount) {
        this.customerCount = customerCount;
    }

    public Integer getTransactionCount() {
        return transactionCount;
    }

    public void setTransactionCount(Integer transactionCount) {
        this.transactionCount = transactionCount;
    }

    public Double getPayPerUnit() {
        return payPerUnit;
    }

    public void setPayPerUnit(Double payPerUnit) {
        this.payPerUnit = payPerUnit;
    }

    public String getPayUnit() {
        return payUnit;
    }

    public void setPayUnit(String payUnit) {
        this.payUnit = payUnit;
    }

    public Integer getMethodId() {
        return methodId;
    }

    public void setMethodId(Integer methodId) {
        this.methodId = methodId;
    }

    public List<BonusPayment> getBonusPayments() {
        return bonusPayments;
    }

    public void setBonusPayments(List<BonusPayment> bonusPayments) {
        this.bonusPayments = bonusPayments;
    }

    public Double getPaidBalance(Integer userId) {
        if ((this.bonusPayments == null) || (this.bonusPayments.size() == 0)) {
            return new Double(0);
        }

        double ret = 0;

        for (BonusPayment p : bonusPayments) {
            if (p.getUserId().equals(userId)) {
                ret += p.getAmount().doubleValue();
            }
        }

        return new Double(ret);
    }

    @Override
    public boolean equals(Object obj) {
        if ((obj == null) ||!(obj instanceof Bonus)) {
            return false;
        }

        Bonus   b  = (Bonus) obj;
        boolean eq = ((id == null) && (b.id == null)) || ((id != null) && id.equals(b.id));

        if (!eq) {
            return false;
        }

        eq = ((name == null) && (b.name == null)) || ((name != null) && name.equals(b.name));

        if (!eq) {
            return false;
        }

        eq = ((description == null) && (b.description == null))
             || ((description != null) && description.equals(b.description));

        if (!eq) {
            return false;
        }

        eq = ((typeId == null) && (b.typeId == null)) || ((typeId != null) && typeId.equals(b.typeId));

        if (!eq) {
            return false;
        }

        eq = ((operator == null) && (b.operator == null)) || ((operator != null) && operator.equals(b.operator));

        if (!eq) {
            return false;
        }

        if (active != b.active) {
            return false;
        }

        eq = ((tableName == null) && (b.tableName == null)) || ((tableName != null) && tableName.equals(b.tableName));

        if (!eq) {
            return false;
        }

        eq = ((columnName == null) && (b.columnName == null))
             || ((columnName != null) && columnName.equals(b.columnName));

        if (!eq) {
            return false;
        }

        eq = ((details == null) && (b.details == null)) || ((details != null) && details.equals(b.details));

        if (!eq) {
            return false;
        }

        eq = ((providerCount == null) && (b.providerCount == null))
             || ((providerCount != null) && providerCount.equals(b.providerCount));

        if (!eq) {
            return false;
        }

        eq = ((customerCount == null) && (b.customerCount == null))
             || ((customerCount != null) && customerCount.equals(b.customerCount));

        if (!eq) {
            return false;
        }

        eq = ((transactionCount == null) && (b.transactionCount == null))
             || ((transactionCount != null) && transactionCount.equals(b.transactionCount));

        if (!eq) {
            return false;
        }

        eq = ((payPerUnit == null) && (b.payPerUnit == null))
             || ((payPerUnit != null) && payPerUnit.equals(b.payPerUnit));

        if (!eq) {
            return false;
        }

        eq = ((payUnit == null) && (b.payUnit == null)) || ((payUnit != null) && payUnit.equals(b.payUnit));

        if (!eq) {
            return false;
        }

        eq = ((methodId == null) && (b.methodId == null)) || ((methodId != null) && methodId.equals(b.methodId));

        if (!eq) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int prime  = 31;
        int result = 1;

        result = prime * result + ((id == null)
                                   ? 0
                                   : id.hashCode());
        result = prime * result + ((name == null)
                                   ? 0
                                   : name.hashCode());
        result = prime * result + ((description == null)
                                   ? 0
                                   : description.hashCode());
        result = prime * result + ((typeId == null)
                                   ? 0
                                   : typeId.hashCode());
        result = prime * result + ((active == false)
                                   ? 0
                                   : 1);
        result = prime * result + ((tableName == null)
                                   ? 0
                                   : tableName.hashCode());
        result = prime * result + ((columnName == null)
                                   ? 0
                                   : columnName.hashCode());
        result = prime * result + ((details == null)
                                   ? 0
                                   : details.hashCode());
        result = prime * result + ((providerCount == null)
                                   ? 0
                                   : providerCount.hashCode());
        result = prime * result + ((customerCount == null)
                                   ? 0
                                   : customerCount.hashCode());
        result = prime * result + ((transactionCount == null)
                                   ? 0
                                   : transactionCount.hashCode());
        result = prime * result + ((payPerUnit == null)
                                   ? 0
                                   : payPerUnit.hashCode());
        result = prime * result + ((payUnit == null)
                                   ? 0
                                   : payUnit.hashCode());
        result = prime * result + ((methodId == null)
                                   ? 0
                                   : methodId.hashCode());

        return result;
    }
}



